<?php
/*
 * Process ajax requests.
 */

// Set Paths
$mod_path = $modx->config['base_path'] . 'assets/modules/foxyback/';
include_once $mod_path.'/config.inc.php';
include_once $mod_path.'/foxyback.class.inc.php';
include_once $mod_path.'/notify.inc.php';

$foxyback = new FoxyBack();

$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : 'default';

$output = '';

if ($action == 'order_status_edit') {
	$transaction_id = $_REQUEST['transaction_id'];
	$order_status_id = $_REQUEST['order_status_id'];
	$status_notes = $_REQUEST['status_notes'];

	if ($transaction_id == '' || $order_status_id == '') {
		$output = '<span class="messageError">Missing required parameter.</span>';
		return $output;
	}

	$edit_spec = array(
		'order_status_id' => $order_status_id,
		'status_notes' => $status_notes,
	);

	// Edit this transaction to the new status.
	$edit_id = $foxyback->editTransaction($transaction_id, $edit_spec);
	if (!$edit_id) {
		$output = '<span class="messageError">Error while updating transaction '.$transaction_id.'!</span>';
		return $output;
	}

	$output = '<span class="messageGood">Update of transaction '.$transaction_id.' was successful.</span>';
}
else {
	$output = '<span class="messageError">Error, the requested action is not valid.</span>';
}

return $output;

?>
